package com.wica.adapter;

import com.wica.view.ELMostViewed;
import com.wica.view.EfficientList;
import com.wica.view.MoodDialog;
import com.wica.view.TextLocationDialog;

import android.content.Context;
import android.content.Intent;
import android.preference.PreferenceManager;
import android.util.Log;

public class ELAMostViewed extends EfficientListAdapter{
	// *************** Constants ************** //  
    // Set up a random unique ID for message handler
    protected static final int GUIUPDATEIDENTIFIER = 12345;
	// Log constant
	private static final String LOG_TAG = "__FT.ELAMostViewed__";

    // *************** Attributes ************************* //  
	/* Attributes: (regarding FaceTube WebService) */
    /** numberOfResults: Integer -- 0..30 (regarding FaceTube WebService)**/
	private Integer numberOfResults;
	/** 	time: String 			(regarding FaceTube WebService)	 
	 * 								-- All Time:   "all_time"  ""  null
	 * 								-- This Month: "this_month"
	 * 								-- This Week:  "this_week"
	 * 								-- Today:	   "today"
	 **/
	private String time;

	// *************** Methods **************************** //

    // *************** Creation methods ************** //  
	public ELAMostViewed(ELMostViewed list) {
		super(list);	
		Log.v(LOG_TAG, LOG_TAG+"ELAMostViewed"+list);
		this.list=(EfficientList)list;
		this.adapter=this;
		this.numberOfResults=Integer.valueOf(PreferenceManager.getDefaultSharedPreferences((Context)list).getString("most_viewed_numberOfResults", "10"));
		this.time=PreferenceManager.getDefaultSharedPreferences((Context)list).getString("most_viewed_time", "today");		
		getListOfVideosThread();		
	}// ELAMostViewed method	
	
    // *************** Functional methods ************** //
    
	@Override
    protected void getListOfVideosMethod() {
		super.getListOfVideosMethod();
		listOfMovies = fts.getMostViewed(numberOfResults, time);
	}// getListOfVideosMethod method
	
    @Override
    protected void checkPreconditions() {
		if (time.compareTo("all_time")!=0 && time.compareTo("")!=0 && time!=null && time.compareTo("this_month")!=0 && time.compareTo("this_week")!=0 && time.compareTo("today")!=0){
			Log.e(LOG_TAG, "Not a valid \"time\" parameter when calling "+"EfficientListAdapter"+"->"+"getMostViewed"+"\nIt should be: \"all_time\",\"\",null,\"this_month\",\"this_week\",\"today\"");			
			System.exit(-1);
		}
	}// checkPreconditions method
    
    
    @Override
	public void refresh(){
		if ((this.numberOfResults!=(Integer.valueOf(PreferenceManager.getDefaultSharedPreferences((Context)list).getString("most_viewed_numberOfResults", "10"))))||(this.time!=PreferenceManager.getDefaultSharedPreferences((Context)list).getString("most_viewed_time", "today"))){
			this.numberOfResults=Integer.valueOf(PreferenceManager.getDefaultSharedPreferences((Context)list).getString("most_viewed_numberOfResults", "10"));
			this.time=PreferenceManager.getDefaultSharedPreferences((Context)list).getString("most_viewed_time", "today");
			Log.v(LOG_TAG, LOG_TAG+" "+numberOfResults+" "+time);
			getListOfVideosThread();	
		}		
    }
    
    // *************** Set methods ************** //  
	public void setNumberOfResults(Integer numberOfResults){
    	this.numberOfResults = numberOfResults;
    }// setNumberOfResults method	
    
    public void setTime(String time){
    	this.time = time;
    }// setTime method
    
	
    // *************** Get methods ************** //  
	public Integer getNumberOfResults(){
    	return(this.numberOfResults);
    }// getNumberOfResults method	
    
    public String getTime(){
    	return (this.time);
    }// getTime method    

}// ELAMostViewed class